// RegFreeCom.h : Declaration of the CRegFreeCom

#pragma once
#include "resource.h"       // main symbols
#include <ppltasks.h>


#include "ManifestCOM_i.h"
#include "_IRegFreeComEvents_CP.h"

using namespace concurrency;


#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

using namespace ATL;


// CRegFreeCom

class ATL_NO_VTABLE CRegFreeCom :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CRegFreeCom, &CLSID_RegFreeCom>,
	public IConnectionPointContainerImpl<CRegFreeCom>,
	public CProxy_IRegFreeComEvents<CRegFreeCom>,
	public IDispatchImpl<IRegFreeCom, &IID_IRegFreeCom, &LIBID_ManifestCOMLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CRegFreeCom()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_MANIFESTCOM)

DECLARE_NOT_AGGREGATABLE(CRegFreeCom)

BEGIN_COM_MAP(CRegFreeCom)
	COM_INTERFACE_ENTRY(IRegFreeCom)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CRegFreeCom)
	CONNECTION_POINT_ENTRY(__uuidof(_IRegFreeComEvents))
END_CONNECTION_POINT_MAP()


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

	//[id(1), helpstring("Sum")] HRESULT Sum([in] int a, [in] int b, [out, retval] int* result);
	HRESULT STDMETHODCALLTYPE Sum(int a, int b, int* result)
	{
		*result = a + b;

		return S_OK;
	}

	//[id(2), helpstring("SumAsync")] HRESULT SumAsync([in] int a, [in] int b);
	HRESULT STDMETHODCALLTYPE SumAsync(int a, int b)
	{
		task<void> t([this, a, b]()
		{
			Sleep(100);
			Fire_onSumAsyncDone(a, b, a + b);
		});

		return S_OK;
	}

public:
	
};

OBJECT_ENTRY_AUTO(__uuidof(RegFreeCom), CRegFreeCom)
